package com.dzb.langchain4j.controller;

import com.dzb.langchain4j.entity.AdmissionStatus;
import com.dzb.langchain4j.enums.AdmissionStatusEnum;
import com.dzb.langchain4j.service.AdmissionStatusService;
import com.dzb.langchain4j.vo.AdmissionStatusVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 录取状态控制器示例
 */
@RestController
@RequestMapping("/api/admission-status")
public class AdmissionStatusController {
    
    @Autowired
    private AdmissionStatusService admissionStatusService;
    
    /**
     * 获取录取状态详情（返回VO，包含中文描述）
     */
    @GetMapping("/{id}")
    public AdmissionStatusVO getAdmissionStatus(@PathVariable Integer id) {
        return admissionStatusService.getAdmissionStatusVO(id);
    }
    
    /**
     * 获取录取状态列表（返回VO列表，包含中文描述）
     */
    @GetMapping("/list")
    public List<AdmissionStatusVO> getAdmissionStatusList() {
        return admissionStatusService.getAdmissionStatusVOList();
    }
    
    /**
     * 创建录取状态记录（使用枚举避免魔法值）
     */
    @PostMapping("/create")
    public AdmissionStatus createAdmissionStatus(@RequestParam String name,
                                               @RequestParam Integer age,
                                               @RequestParam String address,
                                               @RequestParam Integer score,
                                               @RequestParam String status) {
        // 根据字符串获取枚举，避免直接使用数字
        AdmissionStatusEnum statusEnum;
        switch (status.toLowerCase()) {
            case "admitted":
                statusEnum = AdmissionStatusEnum.ADMITTED;
                break;
            case "successful":
                statusEnum = AdmissionStatusEnum.SUCCESSFUL_APPLICATION;
                break;
            case "sliding":
                statusEnum = AdmissionStatusEnum.SLIDING;
                break;
            case "withdrawn":
                statusEnum = AdmissionStatusEnum.WITHDRAWN;
                break;
            default:
                statusEnum = AdmissionStatusEnum.UNKNOWN;
        }
        
        return admissionStatusService.createAdmissionStatus(name, age, address, score, statusEnum);
    }
    
    /**
     * 根据状态码获取状态描述
     */
    @GetMapping("/status/{code}")
    public String getStatusDescription(@PathVariable Integer code) {
        return admissionStatusService.getStatusDescription(code);
    }
    
    /**
     * 检查是否为已录取状态
     */
    @GetMapping("/check-admitted/{code}")
    public boolean isAdmitted(@PathVariable Integer code) {
        return admissionStatusService.isAdmitted(code);
    }
    
    /**
     * 获取所有录取状态枚举
     */
    @GetMapping("/enums")
    public AdmissionStatusEnum[] getAllStatusEnums() {
        return AdmissionStatusEnum.values();
    }
} 